#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

const int N = 1e4 + 10;
int sum[N];
int f[N];
int g[N];

int main() {
    int n;
    cin >> n;

    int x;
    for (int i = 0; i < n; ++i)
    {
        cin >> x;
        sum[x] += x;
    }

    for (int i = 0; i < N; ++i)
    {
        f[i] = sum[i] + g[i - 1];
        g[i] = max(f[i - 1], g[i - 1]);
    }
    cout << max(f[N - 1], g[N - 1]) << endl;

    return 0;
}